# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=pelican
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.2.0
pkgrel=1
pkgdesc='A tool to generate a static blog, with restructured text (or markdown) input files (mingw-w64)'
arch=('any')
url='https://getpelican.com/'
license=('AGPL3')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-jinja"
         "${MINGW_PACKAGE_PREFIX}-python-pygments"
         "${MINGW_PACKAGE_PREFIX}-python-feedgenerator"
         "${MINGW_PACKAGE_PREFIX}-python-pytz"
         "${MINGW_PACKAGE_PREFIX}-python-docutils"
         "${MINGW_PACKAGE_PREFIX}-python-blinker"
         "${MINGW_PACKAGE_PREFIX}-python-unidecode"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-markdown: Markdown support"
            "${MINGW_PACKAGE_PREFIX}-asciidoc: AsciiDoc support"
            "${MINGW_PACKAGE_PREFIX}-python-beautifulsoup4: importing from wordpress/dotclear/posterous"
            #"${MINGW_PACKAGE_PREFIX}-python-feedparser: importing from feeds"
            "${MINGW_PACKAGE_PREFIX}-python-rst2pdf: PDF generation"
            "openssh: uploading through SSH"
            "rsync: uploading through rsync+SSH"
            "lftp: uploading through FTP"
            #"s3cmd: uploading through S3"
            #"${MINGW_PACKAGE_PREFIX}-python-ghp-import: uploading through gh-pages"
            #"${MINGW_PACKAGE_PREFIX}-python-typogrify: typographical enhancements"
            #"${MINGW_PACKAGE_PREFIX}-pandoc: for pelican-import auto convert"
	          #"${MINGW_PACKAGE_PREFIX}-python-mdx-video: easier embedding of youtube videos in markdown"
           )
source=("pelican-${pkgver}.tar.gz"::"https://github.com/getpelican/pelican/archive/${pkgver}.tar.gz")
install=${_realname}-${CARCH}.install
sha256sums=('4b0d4c9439217b49ace89f4f8b52c90e13fa283a786d7b12e2020a11f32f9a33')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "pelican-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build

  msg "Building documentation"
  cd "${srcdir}/python-build-${CARCH}/docs"
  PYTHONPATH="${srcdir}/python-build-${CARCH}/build/lib" \
    make man html
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH="${srcdir}/python-build-${CARCH}/build/lib" \
    ${MINGW_PREFIX}/bin/nosetests
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build
  # fix python command in files
  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  for _ff in "${pkgdir}${MINGW_PREFIX}/bin/*.py"; do
    sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_ff}
  done
  # documentation
  local _docdir="${srcdir}/python-build-${CARCH}/docs/_build"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/man/man1"
  for _ff in "${_docdir}/man/*.1"
  do
    cp ${_ff} "${pkgdir}${MINGW_PREFIX}/share/man/man1/"
  done
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc"
  cp -r "${_docdir}/html/" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  # license
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
